package com.zy.nft_system.domain;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 这是那头猪？
 * @version 1.0
 * @description: TODO
 * @date 2022/9/28 12:41
 */
@Component
@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class Result<T> {
    //响应状态码
    private int code;
    //响应信息
    private String message;
    //数据
    private T data;
    //动态数据
    private Map map = new HashMap();

    //封装正确的响应信息
    public static <T> Result<T> success(String message,T object) {
        Result<T> r = new Result<T>();
        r.message = message;
        r.data = object;
        r.code = 1;
        return r;
    }
    //封装错误的响应信息
    public static <T> Result<T> error(String message) {
        Result r = new Result();
        r.message = message;
        r.code = 0;
        return r;
    }

    //添加数据
    public Result<T> add(String key, Object value) {
        this.map.put(key, value);
        return this;
    }
}
